package com.wowangz.cms.systemmanage.report.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.report.pojo.Report;

public class ReportService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(ReportService.class);
	
	/**
	 * 新增报表信息
	 * @param province
	 * @throws Exception
	 */
	public void add(Report report) throws ServiceException {
		try {
			this.getSqlSession().insert("Report.insertReport", report);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("Report.queryReportCount", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return countNum;
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<Report> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<Report> list = null;
		try {
			list = this.getSqlSession().selectList("Report.queryReportPage", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return list;
	}
	
	/**
	 * 验证信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean validationReport(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("Report.validationReport", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}
	
	public Report findReportById(String id) throws ServiceException {
		Report report = null;
		try {
			report = this.getSqlSession().selectOne("Report.findReportById", id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return report;
	}
	
	public void update(Report report) throws ServiceException {
		try {
			this.getSqlSession().update("Report.updateReport", report);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 报表启用
	 * @param report
	 * @throws ServiceException
	 */
	public void reportStart(Report report) throws ServiceException {
		try {
			this.getSqlSession().update("Report.updateReport", report);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
}
